package leetcode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0376.java
 * @Author : WangRuoyu
 * @Date 2023/11/1 22:18
 */


public class Q0376 {
    public int wiggleMaxLength(int[] nums) {
        if (nums.length == 1) return 1;

        int prediff = nums[1] - nums[0];
        int res = prediff == 0 ? 1 : 2;

        for (int i = 2; i < nums.length; i++) {
            int diff = nums[i] - nums[i - 1];
            if (diff != 0 && diff * prediff <= 0) {
                res++;
                prediff = diff;
            }
        }

        return res;
    }

    public static void main(String[] args) {
        Q0376 sl = new Q0376();
        int[] nums = {1, 7, 4, 9, 2, 5};
        System.out.println(sl.wiggleMaxLength(nums));
    }
}